<?php

/**
 * This is the model class for table "tbl_statuscode".
 *
 * The followings are the available columns in table 'tbl_statuscode':
 * @property string $statuscode
 * @property string $dispatchdate
 * @property string $dispatchtime
 * @property string $name
 * @property string $timeon
 * @property string $timeoff
 * @property string $transfer
 * @property string $leave
 * @property string $setassign
 * @property string $setunassign
 * @property string $complcode
 * @property string $order
 * @property integer $mobile
 * @property integer $statusbillable
 */
class Statuscode extends CanLockRecord
{
	/**
	 * Returns the static model of the specified AR class.
	 * @return Statuscode the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'tbl_statuscode';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('statuscode, dispatchdate, dispatchtime, name, timeon, timeoff, leave, setassign, setunassign, order, mobile, statusbillable', 'required'),
			array('mobile, statusbillable', 'numerical', 'integerOnly'=>true),
			array('statuscode, complcode', 'length', 'max'=>15),
			array('dispatchdate, dispatchtime, name, timeon, timeoff, leave, setassign, setunassign', 'length', 'max'=>1),
			array('transfer, order', 'length', 'max'=>4),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('statuscode, dispatchdate, dispatchtime, name, timeon, timeoff, transfer, leave, setassign, setunassign, complcode, order, mobile, statusbillable', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'statuscode' => 'Statuscode',
			'dispatchdate' => 'Dispatchdate',
			'dispatchtime' => 'Dispatchtime',
			'name' => 'Name',
			'timeon' => 'Timeon',
			'timeoff' => 'Timeoff',
			'transfer' => 'Transfer',
			'leave' => 'Leave',
			'setassign' => 'Setassign',
			'setunassign' => 'Setunassign',
			'complcode' => 'Complcode',
			'order' => 'Order',
			'mobile' => 'Mobile',
			'statusbillable' => 'Statusbillable',
		);
	}

	public static function getList(){
            $list=Yii::app()->db->createCommand('select statuscode from tbl_statuscode order by `order`')->queryAll();
            $rs=array();
            foreach($list as $item){
                $rs[$item['statuscode']]=$item['statuscode'];
            }
            return $rs;
        }
        public static function getIcon($statuscode){
            $check=Yii::app()->db->createCommand('select count(statuscode) from tbl_statuscode where statuscode=:code')
                    ->bindValue('code', $statuscode)->queryScalar();
            if($check>0){
                return $statuscode.'.png';
            }
            return '';
        }
}